package com.zhuyi.broadcast.controller;

import com.zhuyi.broadcast.pojo.domain.AuditRecord;
import com.zhuyi.broadcast.pojo.domain.AuditTask;
import com.zhuyi.broadcast.pojo.domain.Program;
import com.zhuyi.broadcast.service.AuditService;
import com.zhuyi.common.core.controller.BaseController;
import com.zhuyi.common.core.domain.AjaxResult;
import com.zhuyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  审核Controller
 * </p>
 *
 * @author dyj
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/audit")
public class AuditController extends BaseController {

    @Autowired
    private AuditService auditService;

    /**
     * 提交审核任务
     * @param auditTask
     * @return
     */
    @PostMapping("/submit")
    public AjaxResult submitAuditTask(@RequestBody AuditTask auditTask) {
        return auditService.submitAuditTask(auditTask);
    }

    /**
     * 审核任务
     * @param taskId
     * @param auditorId
     * @param result
     * @param comments
     * @return
     */
    @PostMapping("/approve")
    public AjaxResult auditTask(@RequestParam Long taskId,
                                @RequestParam Long auditorId,
                                @RequestParam String result,
                                @RequestParam(required = false) String comments) {
        return auditService.auditTask(taskId, auditorId, result, comments);
    }

    /**
     * 获取待审核任务
     * @return
     */
    @GetMapping("/pending")
    public AjaxResult getPendingTasks() {
        List<AuditTask> tasks = auditService.getPendingTasks();
        return success(tasks);
    }

    /**
     * 获取所有审核任务
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(AuditTask auditTask) {
        startPage();//开启分页
        List<AuditTask> list = auditService.list(auditTask);
        return getDataTable(list);// 返回分页数据
    }
}


